<%@ page language="java" import="java.util.*,java.text.*" pageEncoding="utf-8"%>
<%@ page import="com.example.meal_ordering_system.entity.Users" %>

<%
	// 检查用户会话是否存在，如果不存在，重定向到登录页面
	Users user = (Users) session.getAttribute("user_session");
	if (user == null) {
		response.sendRedirect("login.jsp"); // 重定向到登录页面
		return; // 终止后续代码执行
	}
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>User Center</title>
	<link href="${pageContext.request.contextPath}/public/qiantai/css/common.css" rel="stylesheet" type="text/css" />
</head>

<script type="text/javascript" src="${pageContext.request.contextPath}/public/qiantai/js/common.js"></script>

<script language="JavaScript">
	function check11() {
		if (document.form1.name.value == "") {
			alert("Username cannot be empty!");
			document.form1.name.focus();
			return false;
		}
		if (document.form1.pwd.value == "") {
			alert("Password cannot be empty!");
			document.form1.pwd.focus();
			return false;
		}
		if (document.form1.qpwd.value == "") {
			alert("Confirm Password cannot be empty!");
			document.form1.qpwd.focus();
			return false;
		}
		if (document.form1.qpwd.value != document.form1.pwd.value) {
			alert("Passwords do not match!");
			document.form1.qpwd.focus();
			return false;
		}
		if (document.form1.realname.value == "") {
			alert("Full Name cannot be empty!");
			document.form1.realname.focus();
			return false;
		}
		if (document.form1.age.value == "") {
			alert("Age cannot be empty!");
			document.form1.age.focus();
			return false;
		}
		if (document.form1.card.value == "") {
			alert("ID Card Number cannot be empty!");
			document.form1.card.focus();
			return false;
		}
		if (document.form1.address.value == "") {
			alert("Address cannot be empty!");
			document.form1.address.focus();
			return false;
		}
		if (document.form1.phone.value == "") {
			alert("Phone Number cannot be empty!");
			document.form1.phone.focus();
			return false;
		}
		if (document.form1.email.value == "") {
			alert("Email cannot be empty!");
			document.form1.email.focus();
			return false;
		}
		if (document.form1.code.value == "") {
			alert("Postal Code cannot be empty!");
			document.form1.code.focus();
			return false;
		}
	}
</script>

<body style='background:transparent'>
<table width="900" border="0" align="center" cellpadding="0" cellspacing="0">
	<tr>
		<td align="left" valign="top">
			<jsp:include flush="false" page="top.jsp"/>
		</td>
	</tr>
	<tr>
		<td height="20"></td>
	</tr>

	<tr>
		<td align="center" valign="center" height="450">

			<form action="/users/update" name="form1" method="post" onSubmit="return check11()">

				<div align="center"><br>
					<table border="1" cellspacing="0" bordercolorlight="#C0C0C0" bordercolordark="#C0C0C0" width="700">
						<tr>
							<td colspan="3" align="center" height="25">
								<font color="#666666">Please fill in user information (<font color="red">*</font> indicates required field)</font>
							</td>
						</tr>
						<tr>
							<td align="right"><font color="#996633">Username:</font></td>
							<td align="left"><font color="red"><%=user.getName()%></font></td>
							<td align="left"><font color="red">&nbsp;* </font>Your login username</td>
						</tr>
						<tr>
							<td align="right"><font color="#996633">Password:</font></td>
							<td align="left"><input class="input7" type="password" name="pwd" value="<%=user.getPwd() %>"/></td>
							<td align="left"><font color="red">&nbsp;* </font>Must be between 5 and 16 characters, containing only letters and numbers</td>
						</tr>
						<tr>
							<td align="right"><font color="#996633">Confirm Password:</font></td>
							<td align="left"><input class="input7" type="password" name="qpwd" value="<%=user.getPwd()%>"/></td>
							<td align="left"><font color="red">&nbsp;* </font>Enter the password again</td>
						</tr>
						<tr>
							<td align="right"><font color="#996633">Full Name:</font></td>
							<td align="left"><input class="input7" type="text" name="realname" value="<%=user.getRealname()%>"/></td>
							<td align="left"><font color="red">&nbsp;* </font>Enter your real full name</td>
						</tr>
						<tr>
							<td align="right"><font color="#996633">Gender:</font></td>
							<td align="left">
								<%
									if(user.getSex().equals("男")){
								%>
								<font color="red">Male</font>
								<%
								}else{
								%>
								<font color="red">Female</font>
								<%} %>
							</td>
							<td align="left"><font color="red">&nbsp;* </font>Enter your real information</td>
						</tr>
						<tr>
							<td align="right"><font color="#996633">Age:</font></td>
							<td align="left"><input class="input7" type="text" name="age" value="<%=user.getAge()%>"/></td>
							<td align="left"><font color="red">&nbsp;* </font>Enter your real age</td>
						</tr>
						<tr>
							<td align="right"><font color="#996633">ID Card Number:</font></td>
							<td align="left"><input class="input7" type="text" name="card" value="<%=user.getCard()%>"/></td>
							<td align="left"><font color="red">&nbsp;* </font>Enter your real ID card number</td>
						</tr>
						<tr>
							<td align="right"><font color="#996633">Address:</font></td>
							<td align="left"><input class="input7" type="text" name="address" value="<%=user.getAddress()%>"/></td>
							<td align="left"><font color="red">&nbsp;* </font>Enter your home address</td>
						</tr>
						<tr>
							<td align="right"><font color="#996633">Phone Number:</font></td>
							<td align="left"><input class="input7" type="text" name="phone" value="<%=user.getPhone()%>"/></td>
							<td align="left"><font color="red">&nbsp;* </font>Enter a valid phone number (e.g., 02411111111 or 13911111111)</td>
						</tr>
						<tr>
							<td align="right"><font color="#996633">Email:</font></td>
							<td align="left"><input class="input7" type="text" name="email" value="<%=user.getEmail()%>"/></td>
							<td align="left"><font color="red">&nbsp;* </font>Provide a valid email address for better service</td>
						</tr>
						<tr>
							<td align="right"><font color="#996633">Postal Code:</font></td>
							<td align="left"><input class="input7" type="text" name="code" value="<%=user.getCode()%>"/></td>
							<td align="left"><font color="red">&nbsp;* </font>Enter your postal code (e.g., 111111)</td>
						</tr>
						<tr><input type="hidden" name="id" value="<%=user.getId() %>">
							<td colspan="3" align="center"><input type="submit" value="Update" /></td>
						</tr>
					</table>
				</div>
			</form>
		</td>
	</tr>
	<tr>
		<td height="10">&nbsp;</td>
	</tr>
	<tr>
		<td height="50" align="center" valign="middle">
			<jsp:include flush="false" page="copyright.jsp"/>
		</td>
	</tr>
</table>
</body>
</html>
